package com.plwf.lake.service.impl;

import com.plwf.lake.entity.Reverse;
import com.plwf.lake.mapper.ClassInfoMapper;
import com.plwf.lake.mapper.ReverseMapper;
import com.plwf.lake.service.ReverseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;

@Service
public class ReverseServiceImpl implements ReverseService{
    @Resource
    private ReverseMapper mapper;
    @Resource
    private ClassInfoMapper dao;

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean save(Reverse bean) {
        Boolean flag = false;
        Integer cId = bean.getClassId();
        if(dao.updReve(cId)){
            if(this.mapper.insert(bean)){
                flag =  true;
            }else{
                flag = false;
            }
        }else{
            flag = false;
        }
        return flag;

    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean remove(Reverse bean) {
        Boolean flag = false;
        Integer id = bean.getId();
        Integer classId = bean.getClassId();
        if(dao.deleteRes(classId)){
            if(this.mapper.delete(id)){
                flag = true;
            }else{
                flag = false;
            }
        }else{
            flag = false;
        }
        return flag;

    }

    @Override
    public boolean saveComm(Reverse bean) {
        return this.mapper.insComm(bean);
    }

    @Override
    public boolean removeComm(Integer id) {
        return this.mapper.delComm(id);
    }


}
